<script type="text/javascript">

$(document).ready(function () {
	$('#ruser').select();

	$('#submit_recommendation').click(function(){
		//$("#submit_display").empty();
		//$("#submit_display").append("<img id='theImg' src='<?php echo base_url();?>application/views/images/ajax-loader.gif'/>");
		
		if($('#ruser').val()!=""){
			var form_data = {
				username: $('#ruser').val(),
				restaurant_name: "<?php echo $recommended_restaurant;?>",
				msg: $('#rmsg').val()
			};
			
			$.ajax({
	           url: "<?php echo site_url('account/send_recommendation');?>",
			   type: 'POST',
	           data: form_data,
	           dataType: 'json',
	           
	           success: function (msg) {
	        		var my_window = add_window(170,60,"Alert");
	        		$(my_window).css("left", 80);
	        		$(my_window).css("top", 80);
					$(my_window).append("Message successfully sent");
					var _window = $('#submit_recommendation').closest("div");
					close_window(_window);
	           }
	         });
		}
		else{
			$("#ruser_display").empty();
			$("#ruser_display").append("<div style='color: orange;'>Name is required</div>");
			$("#submit_recommendation_display").empty();
			$("#submit_recommendation_display").append("<div style='color: orange;'>Error</div>");
		}
		 
		return false;
	});

	$('#ruser').keyup(function () {
		
		var form_data = {
			name: $('#ruser').val()
			//email2: $('#email2').val()
		};

		if($('#ruser').val()!=""){
			$.ajax({
	           url: "<?php echo site_url('account/check_username_no_regexp/null');?>",
			   type: 'POST',
	           data: form_data,
	           
	           success: function (msg){
					var _text = "error";
					var _color = "red";
					if(msg=="letter"){
						_text = "Invalid characters";
						_color = "orange";
					}
					else if(msg=="taken"){
						_text = "User exists";
						_color = "green";
					}
					else{
						_text = "No user";
						_color = "orange";
					}
					$("#ruser_display").empty();
					$("#ruser_display").append("<div style='color: "+_color+";'>"+_text+"</div>");
	           }
	         });
		}
		else{
			$("#ruser_display").empty();
		}
		 
		return false;
	});

});

</script>